package se.webbzon.oschi01.world;

import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.List;

public class DefaultDimension implements Dimension {
	
	private List<Region> regions = new ArrayList<Region>();
	
	private String name;
	
	public DefaultDimension(String name) {
		this.name = name;
	}
	
	@Override public boolean hasRegion(Region region) {
		return regions.contains(region);
	}

	@Override public String getName() {
		return name;
	}

	@Override public void setName(String name) {
		this.name = name;
	}

	@Override public int regions() {
		return regions.size();
	}

	@Override public Region getRegion(int index) {
		return regions.get(index);
	}

	@Override public boolean addRegion(Region region) {
		return regions.add(region);
	}

	@Override public boolean removeRegion(Region region) {
		return regions.remove(region);
	}

	@Override public Region getRegion(Point2D coordinate) {
		for (Region r : regions) {
			if (r.getCoordinate().equals(coordinate))
				return r;
		}
		return null;
	}	
	
	@Override public String toString() {
		String name = getName();
		if (name != null && name.isEmpty())
			return "Overworld";
		else
			return name;
	}

}
